/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package centerberg.engine;

import java.awt.Graphics;
import java.awt.Image;
import java.awt.image.BufferedImage;
import java.awt.image.ImageObserver;

/**
 * 
 * 
 * @author Andreas Svanberg
 */
class TiledTexture extends Texture
{
    Image tiledImage;
    
    public TiledTexture(Image baseImage, int w, int h)
    {
        super(baseImage, w, h);
        
        tiledImage = new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB);
        tiledImage.getGraphics().drawImage(baseImage, 0, 0, this);
    }
    
    @Override
    public Image getImage()
    {
        return tiledImage;
    }
    
    @Override
    public boolean imageUpdate(Image image, int infoflags, int x, int y, int width, int height)
    {
        if ((infoflags & ImageObserver.ALLBITS) == 0)
            return true;
        
        Graphics g = tiledImage.getGraphics();
        for (int dx = 0; dx < getSize().width; dx += width)
            for (int dy = 0; dy < getSize().height; dy += height)
                g.drawImage(image, dx, dy, this);
        
        return false;
    }
}
